import type { ParamDeclare, ReturnDeclare } from "../data/var_declare";
import type { TypeTemplate } from "../types/type_template";
import type { PyPkg } from "./PyPkg";
import type { PyVar } from "./PyVar";

export class PyFuncSign {
  constructor(
    public name: string,
    public params: ParamDeclare[] = [],
    public returns: ReturnDeclare[] = [],
  ) {}

  get expression(): string {
    const paramsExp = this.params.map(x => x.name).join(', ')
    return `def ${this.name}(${paramsExp}):`
  }
}

export interface PyFuncInit {
  sign: PyFuncSign,
  implement: string,
  dependencies?: (PyPkg | PyVar | PyFunc)[],
  isPure?: boolean,
  typeTemplates?: TypeTemplate[]
}

export class PyFunc {

  sign: PyFuncSign
  implement: string
  dependencies: (PyPkg | PyVar | PyFunc)[]
  isPure: boolean
  typeTemplates: TypeTemplate[]

  constructor(
    init: PyFuncInit
  ) {
    this.sign = init.sign
    this.implement = init.implement
    this.dependencies = init.dependencies ?? []
    this.isPure = init.isPure ?? false
    this.typeTemplates = init.typeTemplates ?? []
  }

  get expression(): string {
    return this.implement
  }
}
